<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: print_product_info.php 197 2013-09-22 07:58:20Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 197 $
* 	zuletzt geaendert von:	$Author: peter $
* 	Datum:					$Date: 2013-09-22 07:58:20 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include ('includes/application_top.php');

require_once (DIR_FS_INC.'inc.get_products_mo_images.php');
require_once (DIR_FS_INC.'inc.get_vpe_name.php');

$smarty = new Smarty;

$product_info = $db->db_query("SELECT
									*
								FROM
									".TABLE_PRODUCTS." p,
									".TABLE_PRODUCTS_DESCRIPTION." pd
								WHERE
									p.products_status = '1'
								AND
									p.products_id = '".(int)$_GET['products_id']."'
								AND
									pd.products_id = p.products_id
								AND
									pd.language_id = '".(int)$_SESSION['languages_id']."'");


$products_price = $price->GetPrice($product_info->fields['products_id'], true, 1, $product_info->fields['products_tax_class_id'], $product_info->fields['products_price'], 1);

$products_attributes = $db->db_query("SELECT
											COUNT(*) AS total
										FROM
											".TABLE_PRODUCTS_OPTIONS." popt,
											".TABLE_PRODUCTS_ATTRIBUTES." patrib
										WHERE
											patrib.products_id = '".(int) $_GET['products_id']."'
										AND
											patrib.options_id = popt.products_options_id
										AND
											popt.language_id = '".(int) $_SESSION['languages_id']."'");

if ($products_attributes->fields['total'] > 0) {
	$products_options_name = $db->db_query("SELECT DISTINCT
												popt.products_options_id,
												popt.products_options_name
											FROM
												".TABLE_PRODUCTS_OPTIONS." popt,
												".TABLE_PRODUCTS_ATTRIBUTES." patrib
											WHERE
												patrib.products_id = '".(int)$_GET['products_id']."'
											AND
												patrib.options_id = popt.products_options_id
											AND
												popt.language_id = '".(int) $_SESSION['languages_id']."'
											ORDER BY
												popt.products_options_name");
	while(!$products_options_name->EOF) {
		$selected = 0;

		$products_options = $db->db_query("SELECT
												pov.products_options_values_id,
												pov.products_options_values_name,
												pa.options_values_price,
												pa.price_prefix,pa.attributes_stock,
												pa.attributes_model
											FROM
												".TABLE_PRODUCTS_ATTRIBUTES." pa,
												".TABLE_PRODUCTS_OPTIONS_VALUES." pov
											WHERE
												pa.products_id = '".(int)$_GET['products_id']."'
											AND
												pa.options_id = '".$products_options_name->fields['products_options_id']."'
											AND
												pa.options_values_id = pov.products_options_values_id
											AND
												pov.language_id = '".(int)$_SESSION['languages_id']."'");

		while (!$products_options->EOF) {
			$module_content[] = array ('GROUP' => $products_options_name->fields['products_options_name'],
										'NAME' => $products_options->fields['products_options_values_name']);

			if ($products_options->fields['options_values_price'] != '0') {
				if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
					$tax_rate = $price->TAX[$product_info->fields['products_tax_class_id']];
					$products_options->fields['options_values_price'] = add_tax($products_options->fields['options_values_price'], $price->TAX[$product_info->fields['products_tax_class_id']]);
				}
				if ($_SESSION['customers_status']['customers_status_show_price'] == 1)
					$module_content[sizeof($module_content) - 1]['NAME'] .= ' ('.$products_options->fields['price_prefix'].$price->format($products_options->fields['options_values_price'], true,0,true).')';

			}
			$products_options->MoveNext();
		}
		$products_options_name->MoveNext();
	}
}

$smarty->assign('language', $_SESSION['language']);

$image = '';
if ($product_info->fields['products_image'] != '') {
	$image = DIR_WS_THUMBNAIL_IMAGES.$product_info->fields['products_image'];
}
if ($_SESSION['customers_status']['customers_status_show_price'] != 0) {
	$tax_rate = $price->TAX[$product_info->fields['products_tax_class_id']];

	if ($tax_rate > 0 && $_SESSION['customers_status']['customers_status_show_price_tax'] != 0)
		$smarty->assign('PRODUCTS_TAX_INFO', sprintf(TAX_INFO_INCL, $tax_rate.' %'));

	if ($tax_rate > 0 && $_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1)
		$smarty->assign('PRODUCTS_TAX_INFO', sprintf(TAX_INFO_ADD, $tax_rate.' %'));

	if ($tax_rate > 0 && $_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0)
		$smarty->assign('PRODUCTS_TAX_INFO', sprintf(TAX_INFO_EXCL, $tax_rate.' %'));
}
$smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE);
$smarty->assign('PRODUCTS_NAME', $product_info->fields['products_name']);
$smarty->assign('PRODUCTS_EAN', $product_info->fields['products_ean']);
$smarty->assign('PRODUCTS_QUANTITY', $product_info->fields['products_quantity']);
$smarty->assign('PRODUCTS_WEIGHT', $product_info->fields['products_weight']);
$smarty->assign('PRODUCTS_STATUS', $product_info->fields['products_status']);
$smarty->assign('PRODUCTS_ORDERED', $product_info->fields['products_ordered']);
$smarty->assign('PRODUCTS_MODEL', $product_info->fields['products_model']);
$smarty->assign('PRODUCTS_DESCRIPTION', $product_info->fields['products_description']);
$smarty->assign('PRODUCTS_IMAGE', $image);
$smarty->assign('PRODUCTS_URL', href_link(FILENAME_PRODUCT_INFO, 'products_id='.$product_info->fields['products_id']));
if(PRICE_AS_IMAGE == 'true')
	$price_img = $products_price;
else
	$price_img = $products_price['formated'];
$smarty->assign('PRODUCTS_PRICE', $price_img);
if (ACTIVATE_SHIPPING_STATUS == 'true') {
	$smarty->assign('SHIPPING_NAME', $main->getShippingStatusName($product_info->fields['products_shippingtime']));
	if ($shipping_status['image'] != '')
		$smarty->assign('SHIPPING_IMAGE', $main->getShippingStatusImage($product_info->fields['products_shippingtime']));
}
if (SHOW_SHIPPING == 'true')
	$smarty->assign('PRODUCTS_SHIPPING_LINK', ' '.SHIPPING_EXCL.' '.SHIPPING_COSTS);


$discount = 0.00;
if ($_SESSION['customers_status']['customers_status_public'] == 1 && $_SESSION['customers_status']['customers_status_discount'] != '0.00') {
	$discount = $_SESSION['customers_status']['customers_status_discount'];
	if ($product_info->fields['products_discount_allowed'] < $_SESSION['customers_status']['customers_status_discount'])
		$discount = $product_info->fields['products_discount_allowed'];
	if ($discount != '0.00')
		$smarty->assign('PRODUCTS_DISCOUNT', $discount.'%');
}

if ($product_info->fields['products_vpe_status'] == 1 && $product_info->fields['products_vpe_value'] != 0.0 && $products_price['plain'] > 0)
	$smarty->assign('PRODUCTS_VPE', $price->format($products_price['plain'] * (1 / $product_info->fields['products_vpe_value']), true).TXT_PER.get_vpe_name($product_info->fields['products_vpe']));

$smarty->assign('module_content', $module_content);

$mo_images = get_products_mo_images($product_info->fields['products_id']);
if(is_array($mo_images)) {
	foreach($mo_images as $img)
		$mo_img[] = array('SRC' => DIR_WS_CATALOG.DIR_WS_THUMBNAIL_IMAGES.$img['image_name']);
		
	$smarty->assign('more_images', $mo_img);
}
if(!CacheCheck())
	$smarty->caching = false;
	
else {
	$smarty->caching = true;
	$smarty->cache_lifetime = CACHE_LIFETIME;
	$smarty->cache_modified_check = CACHE_CHECK;
}
$cache_id = $_SESSION['language'].'_'.$product_info->fields['products_id'];

$smarty->display(CURRENT_TEMPLATE.'/module/print_product_info.html', $cache_id);
?>